package com.uphone.kingmall.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.blankj.utilcode.util.SizeUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.china.zhuoyue.R;
import com.uphone.kingmall.bean.OrderBean;
import com.uphone.kingmall.utils.GlideUtils;

import java.util.List;

/**
 * <pre>
 *     author : 孙增艳
 *     e-mail : sunzengyan@outlook.com
 *     time   : 2019/2/25
 *     desc   :
 *     version: 1.0
 * </pre>
 */
public class RvOrderGoodsAdapter extends BaseQuickAdapter<OrderBean.DataBean.GoodslistBean, BaseViewHolder> {

    private final Context context;
    private final boolean isShare;

    public RvOrderGoodsAdapter(Context context, boolean isShare, @Nullable List<OrderBean.DataBean.GoodslistBean> data) {
        super(R.layout.kingmall_item_order_goods, data);
        this.context = context;
        this.isShare = isShare;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderBean.DataBean.GoodslistBean item) {
        helper.setText(R.id.tv_goods_name, item.getGoodsName() + "")
                .setText(R.id.tv_goods_specification, item.getGoodsSpec() + "")
                .setText(R.id.tv_goods_price, item.getGoodsPerFee() + "")
                .setText(R.id.tv_goods_number, "X" + item.getGoodsNum())
                .addOnClickListener(R.id.tv_order_share);
        ImageView imageView = helper.getView(R.id.iv_goods_image);
        TextView tvOrderShare = helper.getView(R.id.tv_order_share);
        if (isShare) {
            tvOrderShare.setVisibility(View.VISIBLE);
        } else {
            tvOrderShare.setVisibility(View.GONE);
        }
        GlideUtils.getInstance().loadCornerImage(context, item.getGoodsImg(), SizeUtils.dp2px(2), imageView);
    }
}
